<?php

namespace common\models;

use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
/**
 * This is the model class for table "{{%vote}}".
 *
 * @property integer $id
 * @property integer $uid
 * @property string $title
 * @property string $content
 * @property integer $time_start
 * @property integer $time_end
 * @property string $rules
 * @property integer $created_at
 * @property integer $updated_at
 */
class Vote extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%vote}}';
    }

    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid', 'title', 'content', 'rules'], 'required'],
            [['uid'], 'integer'],
            [['content', 'rules', 'time_start', 'time_end'], 'string'],
            [['title'], 'string', 'max' => 200],
        ];
    }


    public function getCategory()
    {
        return $this->hasMany(Category::className(), ['vid' => 'id'])->orderBy('sort desc');
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'uid' => '公众号ID',
            'title' => '标题',
            'content' => '说明',
            'time_start' => '开始时间',
            'time_end' => '结束时间',
            'rules' => '规则',
            'created_at' => '添加时间',
            'updated_at' => '更新时间',
        ];
    }
}
